package com.molyfun.parents.activity.store.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.molyfun.parents.R;
import com.molyfun.parents.rest.bean.GetProductTypeResponse;

import java.util.ArrayList;
import java.util.List;

public class ProductTypeSpinnerAdapter extends BaseAdapter {
    private List<GetProductTypeResponse.ProductType> data;
    private LayoutInflater inflater;
    private Context mContext;

    public ProductTypeSpinnerAdapter(Context context, List<GetProductTypeResponse.ProductType> data) {
        super();
        if (data == null) {
            this.data = new ArrayList<>();
        } else {
            this.data = data;
        }
        mContext = context;
        data.add(0, new GetProductTypeResponse.ProductType("", "全部"));
        this.inflater = LayoutInflater.from(mContext);
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        TextView tv = (TextView) inflater.inflate(R.layout.item_spinner_product_type, null);
        tv.setHeight(mContext.getResources().getDimensionPixelSize(R.dimen.title_tab_height));
        tv.setText(data.get(position).getName());
        return tv;
    }

    public String getTypeCode(int position) {
        return data.get(position).getId();
    }
}
